package com.oasys.controller;

import com.alibaba.fastjson.JSON;
import com.oasys.entity.NoticePageVo;
import com.oasys.entity.NoticePo;
import com.oasys.enums.OaResponseCode;
import com.oasys.service.NoticeService;
import com.oasys.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2022/5/13
 **/
@RestController
@RequestMapping("/noticeInfo")
@Slf4j
@Api("公告管理")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    /**
     * 发布公告
     * @param noticePo no
     * @return bool
     */
    @PostMapping("/publishNotice")
    @ApiOperation("发布公告")
    public ResponseResult<Boolean> publishNotice(@RequestBody NoticePo noticePo){
        log.info("发布信息:{}",noticePo);
        return noticeService.publishNotice(noticePo);
    }

    /**
     * 获取data
     * @param noteVo
     * @return
     */
    @PostMapping("/getNoticeByPage")
    @ApiOperation("分页获取公告数据")
    public ResponseResult<Map<String ,Object>> getNoticeByPage(@RequestBody NoticePageVo noteVo){
        return noticeService.getNoticeByPage(noteVo);
    }

    /**
     * 隐藏note
     * @param noteId
     * @return
     */
    @PostMapping("/hideNotice")
    @ApiOperation("隐藏公告")
    public ResponseResult<Boolean> hideNotice(@RequestBody String noteId){
        String nid = JSON.parseObject(noteId).getObject("noteId",String.class);
        Boolean result = noticeService.hideNotice(Long.parseLong(nid));
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),null,result);
    }

    /**
     * 取消隐藏note
     * @param noteId
     * @return
     */
    @PostMapping("/cancelHideNotice")
    @ApiOperation("取消隐藏公告")
    public ResponseResult<Boolean> cancelHideNotice(@RequestBody String noteId){
        String strNid = JSON.parseObject(noteId).getObject("noteId",String.class);
        log.info("data:{}",strNid);
        Boolean result = noticeService.cancelHideNotice(Long.parseLong(strNid));
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),null,result);
    }

    @GetMapping("/deleteNote")
    @ApiOperation("删除公告")
    public ResponseResult<Boolean> deleteNote(String noteId){
//        String strNid = JSON.parseObject(noteId).getObject("noteId",String.class);
        log.info("data:{}",noteId);
        Boolean result = noticeService.deleteNote(Long.parseLong(noteId));
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),null,result);
    }
}
